package mysql

import (
	"dy/internal/configs/config"

	_ "github.com/go-sql-driver/mysql"
	"xorm.io/xorm"
)

func GetMysqlFactory() (*xorm.Engine, error) {
	//获得json里的配置信息
	conf := config.Conf
	mysql := conf.Mysql
	//构建新引擎
	//mysql,"root:123456@(39.105.120.230:3306)/ms?charset=utf8&parseTime=true&&loc=Local&charset=utf8&collation=utf8_unicode_ci"
	engine, err := xorm.NewEngine(mysql.Driver, mysql.User+":"+mysql.PassWord+"@("+mysql.Host+":"+mysql.Port+")/"+mysql.DbName+"?charset="+mysql.Charset+"&parseTime="+mysql.ParseTime+"&loc=Local&charset=utf8&collation=utf8_unicode_ci")
	if err != nil {
		return nil, err
	}
	//设置是否打印sql语句
	engine.ShowSQL(mysql.ShowSql)

	return engine, nil
}
